package main

import (
	"context"
	"forum/internal/domain/event"
	"forum/ioc"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

func main() {
	//init db
	//init server
	APP := InitWebServer()
	ioc.InitPrometheus()
	tpCancel := ioc.InitOTEL()
	defer func() {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()
		tpCancel(ctx)
	}()
	server := APP.server
	for _, c := range APP.Consumers {
		err := c.Start()
		if err != nil {
			//TODO log
		}
	}

	server.POST("/api/test", func(ctx *gin.Context) {
		ctx.String(http.StatusOK, "HelloGin")
	})
	err := server.Run(":8234")
	if err != nil {
		return
	}
}

type App struct {
	server    *gin.Engine
	Consumers []event.Consumer
}
